<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateScheduleUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('schedule_users', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('shopId')->default(0)->comment('店铺ID');
            $table->unsignedInteger('userId')->default(0)->comment('用户ID');
            $table->unsignedInteger('date')->default(0)->comment('日期');
            $table->unsignedTinyInteger('type')->default(0)->comment('1单次 2组合 3周期');
            $table->unsignedInteger('ruleId')->default(0)->comment('班次ID');
            $table->string('ruleName', 32)->default('')->comment('班次名称');
            $table->time('ruleStart')->default('00:00')->comment('班次开始时间');
            $table->time('ruleEnd')->default('00:00')->comment('班次结束时间');
            $table->string('color', 21)->default('')->comment('班次颜色');

            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->tinyInteger('isDeleted')->comment(0);
            $table->collation = 'utf8mb4_general_ci';
            $table->comment = '排班 - 用户班次表';

            $table->index(['shopId', 'userId'], 'idx_shopId_userId');
            $table->index(['shopId', 'date'], 'idx_shopId_date');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('schedule_users');
    }
}
